﻿using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
using UnityEditorInternal;
using System.Reflection;
using System.Collections.Generic;
#endif

public class SortingLayerAttribute : PropertyAttribute
{
	public SortingLayerAttribute()
	{

	}
}

#if UNITY_EDITOR
[CustomPropertyDrawer(typeof(SortingLayerAttribute))]
public class SortingLayerDrawer : PropertyDrawer
{
	public override void OnGUI (Rect position, SerializedProperty property, GUIContent label)
	{
		System.Type type = typeof(InternalEditorUtility);
		PropertyInfo sortingLayersProperty = type.GetProperty("sortingLayerNames", BindingFlags.Static | BindingFlags.NonPublic);
		List<string> layers = new List<string>((string[])sortingLayersProperty.GetValue(null, new object[0]));

		int n = EditorGUI.Popup(position, label.text, layers.IndexOf(property.stringValue), layers.ToArray());
		if (n != -1)
		{
			property.stringValue = layers[n];
		}
	}
}
#endif
